package com.sjb.mianshiya.config;

import com.jd.platform.hotkey.client.ClientStarter;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author:sjb
 * @CreateTime:2024-11-20
 * @Description: HotKey配置
 * @Version：1.0
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "hotkey")
public class HotKeyConfig {

    private String etcdServer = "http://127.0.0.1:2379";

    private String appName = "mianshiya";

    private int caffeineSize = 10000;

    /**
     * 推送热key的间隔时间
     */
    private long pushPeriod = 1000L;


    /**
     * 初始化Key
     */
    @Bean
    public void initHotKey(){
        ClientStarter.Builder builder = new ClientStarter.Builder();
        ClientStarter build = builder.setEtcdServer(etcdServer)
                .setAppName(appName)
                .setCaffeineSize(caffeineSize)
                .setPushPeriod(pushPeriod)
                .build();
        build.startPipeline();
    }
}
